package com.ruoyi.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.purchase.domain.PurchaseList;
import com.ruoyi.purchase.service.IPurchaseListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 进货单管理Controller
 * 
 * @author zxr
 * @date 2023-06-26
 */
@RestController
@RequestMapping("/purchase/purchaseList")
public class PurchaseListController extends BaseController
{
    @Autowired
    private IPurchaseListService purchaseListService;

    /**
     * 查询进货单管理列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaseList:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseList purchaseList)
    {
        startPage();
        List<PurchaseList> list = purchaseListService.selectPurchaseListList(purchaseList);
        return getDataTable(list);
    }

    /**
     * 导出进货单管理列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaseList:export')")
    @Log(title = "进货单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseList purchaseList)
    {
        List<PurchaseList> list = purchaseListService.selectPurchaseListList(purchaseList);
        ExcelUtil<PurchaseList> util = new ExcelUtil<PurchaseList>(PurchaseList.class);
        util.exportExcel(response, list, "进货单管理数据");
    }

    /**
     * 获取进货单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaseList:query')")
    @GetMapping(value = "/{purchaseListId}")
    public AjaxResult getInfo(@PathVariable("purchaseListId") Integer purchaseListId)
    {
        return success(purchaseListService.selectPurchaseListByPurchaseListId(purchaseListId));
    }

    /**
     * 新增进货单管理
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaseList:add')")
    @Log(title = "进货单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseList purchaseList)
    {
        return toAjax(purchaseListService.insertPurchaseList(purchaseList));
    }

    /**
     * 修改进货单管理
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaseList:edit')")
    @Log(title = "进货单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseList purchaseList)
    {
        return toAjax(purchaseListService.updatePurchaseList(purchaseList));
    }

    /**
     * 删除进货单管理
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaseList:remove')")
    @Log(title = "进货单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseListIds}")
    public AjaxResult remove(@PathVariable Integer[] purchaseListIds)
    {
        return toAjax(purchaseListService.deletePurchaseListByPurchaseListIds(purchaseListIds));
    }
}
